const { SyncLoopHook } = require("tapable");

let count = 0;
class HYCompiler {
  constructor() {
    this.hooks = {
      // loop的特点：如果有返回值为true，那么该事件会一直执行，返回值为undefined或者不返回内容，就退出事件
      syncLoopHook: new SyncLoopHook(["name", "age"]),
    };

    this.hooks.syncLoopHook.tap("event1", (name, age) => {
      if (count < 5) {
        console.log("event1事件执行了", name, age);
        count++;
        return 123;
      }
    });

    this.hooks.syncLoopHook.tap("event2", (name, age) => {
      console.log("event1事件执行了", name, age);
    });
  }
}

setTimeout(() => {
  const compiler = new HYCompiler();
  compiler.hooks.syncLoopHook.call("why", 23);
}, 2000);
